
import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth'
import { Notification } from 'element-ui'
import router from '../router'
import Socket from '@/utils/socket'
import { formatDate } from '@/utils/index.js'
const socket = new Socket()

socket.subscribeMsg('111',function(data,e){
    Notification({
        title: '报警信息',
        type: 'warning',
        dangerouslyUseHTMLString: true,
        message: `<div>地址：${data.comment}</div>
        <div>时间：${formatDate(data.createTime)}</div>
        <div>报警信息：${data.comment}</div>`,
        duration: 0,
        onClick(){
            router.push({path:'/sys_jd/event/alarm'})
        }
    })
})

function connect(){
   const host =  window.location.hostname
    socket.connect(`ws://${host}:9322/webSocket/`+ getToken())
}
function disconnect(){
    socket.disconnect()
}
export default {
    socket,
    connect,
    disconnect
} 
// 
// console.log(socket)
// socket.socketonmessage((e)=>{
//     console.log(e)
// })
// console.log(socket)
